<extend name="Layout:layout" />
<block name="body_main">
    <div class="block box">
        <div class="blank"></div>
        <div id="ur_here">
            当前位置: <a href="{:U('EShop/Index/index')}">首页</a> <code>&gt;</code> 购物流程 
        </div>
    </div>
    <div class="blank"></div>
    <div class="block table">
        <div class="flowBox">
            <h6><span>商品列表</span></h6>
            <table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd">
                <tr>
                    <th bgcolor="#ffffff">商品名称</th>
                    <th bgcolor="#ffffff">市场价</th>
                    <th bgcolor="#ffffff">本店价</th>
                    <th bgcolor="#ffffff">购买数量</th>
                    <th bgcolor="#ffffff">小计</th>
                    <th bgcolor="#ffffff">操作</th>
                </tr>
                <foreach name="list" item="vo">                        
                    <tr>
                        <td bgcolor="#ffffff" align="center" style="width:300px;">
                            <a href="{:U('Product/product','id='.$vo['product_id'])}" target="_blank"><img style="width:80px; height:80px;" src="{$vo.picture_url}" border="0" title="{$vo.title}" /></a><br />
                            <a href="{:U('Product/product','id='.$vo['product_id'])}" target="_blank" class="f6">{$vo.title}</a>
                        </td>
                        <td align="center" bgcolor="#ffffff">￥{$vo.market_price}元</td>
                        <td align="center" bgcolor="#ffffff">￥<span class="price">{$vo.price}</span>元</td>
                        <td align="center" bgcolor="#ffffff">
                            <input type="text" name="number" value="{$vo.number}" size="4" class="inputBg" data-url="{:U('change_number','n=varn&id='.$vo['id'])}"/>
                        </td>
                        <td align="center" bgcolor="#ffffff" class="subtotal">￥<span>{$vo.subtotal}</span>元</td>
                        <td align="center" bgcolor="#ffffff">
                            <a href="{:U('delete_cart','id='.$vo['id'])}" class="lnk-delete-cart f6">删除</a>
                        </td>
                    </tr>
                </foreach>
            </table>
            <script type="text/javascript">
                jQuery('.lnk-delete-cart').click(function () {
                    if (!confirm('您确实要把该商品移出购物车吗？')) {
                        return false;
                    }
                    jQuery.get(jQuery(this).attr('href'), function () {
                        location.reload();
                    })
                    return false;
                })
                jQuery('.inputBg').change(function () {
                    var $tb = jQuery(this);
                    var url = $tb.data('url').replace('varn', $tb.val());
                    jQuery.get(url, function (msg) {
                        $tb.parent().next().find('span').text(msg);
                        get_subtotal_bar();
                    })
                })
            </script>
            <table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd">
                <tr>
                    <td bgcolor="#ffffff">
                        <span id="cart_summary" data-url="{:U('get_cart_summary')}">购物金额小计 ￥0.00元，比市场价 ￥0.00元 节省了 ￥0.00元 (0%)</span></td>
                    <td align="right" bgcolor="#ffffff">
                        <input type="button" value="清空购物车" class="bnt_blue_1" id="btn-clear-cart" data-url="{:U('clear_cart')}" />
                        <input name="submit" type="submit" class="bnt_blue_1" value="更新购物车" id='btn-refresh-cart' />
                    </td>
                </tr>
            </table>
            <input type="hidden" name="step" value="update_cart" />
            <script type="text/javascript">
                jQuery('#btn-refresh-cart').click(function () {
                    location.reload();
                    return false;
                })
                jQuery('#btn-clear-cart').click(function () {
                    if (!confirm('您确定要清空购物车吗?')) {
                        return false;
                    }
                    jQuery.get(jQuery(this).data('url'), function () {
                        location.reload();
                    })
                })
                // 2016-9-3 sochishun added.
                function get_subtotal_bar() {
                    var $span = jQuery('#cart_summary');
                    jQuery.get($span.data('url'), function (msg) {
                        $span.html('购物金额小计 ￥' + msg.amount + '元，比市场价 ￥' + msg.market_amount + '元 节省了 ￥' + msg.save_amount + '元 (' + msg.save_rate + '%)');
                    });
                }
                get_subtotal_bar();
            </script>
            <table width="99%" align="center" border="0" cellpadding="5" cellspacing="0" bgcolor="#dddddd">
                <tr>
                    <td bgcolor="#ffffff"><a href="{:U('Product/products')}"><img src="__THEME__images/continue.gif" alt="continue" /></a></td>
                    <td bgcolor="#ffffff" align="right"><a href="{:U('checkout')}"><img src="__THEME__images/checkout.gif" alt="checkout" /></a></td>
                </tr>
            </table>
        </div>
        <div class="blank"></div>
        <div class="blank5"></div>
    </div>
</block>